<template>
  <div class="app-container">
    <el-row :gutter="20">

      <el-col  :xm="24">
        <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="标题" prop="title">
            <el-input v-model="queryParams.userName" placeholder="请输入标题" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="流程名称" prop="currentStepName">
            <el-input v-model="queryParams.phoneNumber" placeholder="请输入流程名称" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
        
          <el-form-item label="发起时间">
            <el-date-picker
              v-model="dateRange"
              style="width: 240px"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="search" @click="handleQuery">{{ $t('btn.search') }}</el-button>
            <el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="5" class="mb8">
          

          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="approvalList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="标识" align="center" key="id" prop="id" v-if="columns.showColumn('id')" />
          <el-table-column prop="title" label="标题" align="center" v-if="columns.showColumn('title')" />
		   <el-table-column prop="currentStepName" label="当前审批节点" align="center" v-if="columns.showColumn('currentStepName')" />
		    <el-table-column prop="businessCode" label="业务单据号" align="center" v-if="columns.showColumn('businessCode')" />
          <el-table-column prop="status" label="状态" align="center" v-if="columns.showColumn('status')" />
		  <el-table-column prop="creatorName" label="发起人" align="center" v-if="columns.showColumn('creatorName')" />
          <el-table-column label="发起时间" align="center" prop="creationTime" v-if="columns.showColumn('creationTime')" width="160"></el-table-column>
          <el-table-column label="操作" align="left" width="110" class-name="small-padding fixed-width">
            <template #default="scope">
              <el-button text="通过" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:user:edit']"> </el-button>
              <el-button v-if="scope.row.id !== 1" text icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:user:remove']">
              </el-button>
              <el-button
                v-if="scope.row.id !== 1"
                text
                icon="Key"
                title="重置密码"
                @click="handleResetPwd(scope.row)"
                v-hasPermi="['system:user:resetPwd']"></el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
      </el-col>
    </el-row>

   
  </div>
</template>

<script setup name="user">
import { getToken } from '@/utils/auth'
import { listApproval } from '@/api/workflow/approval'
import { ConsoleLogger } from '@microsoft/signalr/dist/esm/Utils';

const { proxy } = getCurrentInstance()

const statusOptions = ref([])
const sexOptions = ref([])

proxy.getDicts('sys_normal_disable').then((response) => {
  statusOptions.value = response.result
})


const launchList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref('')
const dateRange = ref([])


// 列显隐信息
const columns = ref([
  { key: 0, label: `标识`, visible: true, prop: 'id' },
  { key: 1, label: `标题`, visible: true, prop: 'title' },
  { key: 2, label: `流程名称`, visible: true, prop: 'currentStepName' },
  { key: 3, label: `业务单据号`, visible: true, prop: 'businessCode' },
  { key: 4, label: `状态`, visible: true, prop: 'status' },
  { key: 5, label: `发起人`, visible: true, prop: 'creatorName' },
  { key: 6, label: `发起时间`, visible: true, prop: 'creationTime' }
])

const data = reactive({
  form: {},
  queryParams: {
    pageIndex: 0,
    pageSize: 10,
    title: undefined,
    currentStepName: undefined
  }
  
})

const { queryParams, form, rules } = toRefs(data)






/** 查询流程列表 */
function getList() {
  loading.value = true
  listApproval(proxy.addDateRange(queryParams.value, dateRange.value)).then((res) => {
    loading.value = false
    approvalList.value = res.result
    total.value = res.totalCount
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}
/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = []
  proxy.resetForm('queryRef')
  queryParams.value.deptId = undefined
  proxy.$refs.deptTreeRef.setCurrentKey(null)
  handleQuery()
}


/** 选择条数  */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 重置操作表单 */
function reset() {
  form.value = {
    title: undefined,
    currentStepName: undefined
  }
  proxy.resetForm('userRef')
}
/** 取消按钮 */
function cancel() {
  open.value = false
  reset()
}
/** 新增按钮操作 */

getList()
</script>
<style scoped>
.avatar {
  width: 40px;
}
</style>
